<template>
	<div>
		<cl-crud @load="onLoad">
			<template #table-column-key="{scope}">
				<el-tag type="success">{{ scope.row.key }}</el-tag>
			</template>

			<template #table-column-type="{scope}">
				<el-tag v-if="scope.row.type == 0">签到</el-tag>
				<el-tag v-else-if="scope.row.type == 1">每日任务</el-tag>
				<el-tag v-else-if="scope.row.type == 2">首次任务</el-tag>
				<el-tag v-else-if="scope.row.type == 3">长期任务</el-tag>
			</template>

			<template #table-column-status="{scope}">
				<el-tag v-if="scope.row.status == 0">禁用</el-tag>
				<el-tag type="success" v-else-if="scope.row.status == 1">启用</el-tag>
			</template>

			<template #table-column-icon="{scope}">
				<img :src="scope.row.icon" class="table-icon" />
			</template>

			<cl-form ref="cl-form"></cl-form>
		</cl-crud>
	</div>
</template>

<script>
import platform from '@/mixin/platform';

export default {
	data() {
		return {
			crud: null,
			options: [],
			select: {
				filters: ''
			}
		};
	},
	mixins: [platform],
	methods: {
		onLoad({ ctx, app }) {
			this.crud = app;
			ctx.service(this.$service.systemMenagement.mainPerm)
				.set('dict', {
					label: {
						add: '添加权限'
					}
				})
				.set('table', {
					columns: [
						{
							label: '序号',
							type: 'index',
							align: 'center',
							width: 60
						},
						{
							label: '名称',
							prop: 'name',
							align: 'center'
						},
						{
							label: 'LOGO',
							prop: 'icon',
							align: 'center'
						},
						{
							label: '接口地址',
							prop: 'router',
							align: 'center'
						},
						{
							label: '类型',
							prop: 'type',
							align: 'center'
						},
						{
							label: '状态',
							prop: 'status',
							align: 'center'
						}
					],

					op: {
						layout: ['edit', 'delete']
					}
				})
				.set('upsert', {
					props: {
						labelWidth: '112px',
						center: true,
						'custom-class': 'custom-class-dialog-mini'
					},
					items: [
						{
							label: '任务key',
							prop: 'name',
							span: 23,
							component: {
								name: 'el-input',
								attrs: {
									placeholder: '请输入任务key'
								}
							},
							rules: {
								required: true,
								message: '请输入任务key'
							}
						},
						{
							label: 'LOGO',
							prop: 'icon',
							span: 23,
							component: {
								name: 'cl-upload'
							}
						},
						{
							label: '接口地址',
							prop: 'router',
							span: 23,
							component: {
								name: 'el-input',
								attrs: {
									placeholder: '请输入接口地址'
								}
							},
							rules: {
								required: true,
								message: '请输入接口地址'
							}
						},
						{
							label: '类型',
							prop: 'type',
							span: 23,
							component: {
								name: 'el-input',
								attrs: {
									placeholder: '请输入任务名称'
								}
							},
							rules: {
								required: true,
								message: '请输入任务名称'
							}
						},
						{
							label: '状态',
							prop: 'status',
							value: 1,
							component: {
								name: 'el-radio-group',
								options: [
									{
										label: '启用',
										value: 1
									},
									{
										label: '禁用',
										value: 0
									}
								]
							}
						}
					]
				})
				.set('layout', [
					['refresh-btn', 'add-btn', 'query', 'flex1', 'search-key'],
					['data-table'],
					['flex1', 'pagination']
				])
				.done();

			app.refresh();
		}
	}
};
</script>
<style scoped>
.table-icon {
	width: 42px;
	height: auto;
}
</style>
